@import '../core/density/index';
@import '../core/theming/palette';
@import '../core/theming/theming';
@import '../core/theming/check-duplicate-styles';
@import '../core/style/elevation';
@import '../core/typography/typography-utils';
@import './expansion-variables';

@mixin mat-expansion-panel-color($config-or-theme) {
  $config: mat-get-color-config($config-or-theme);
  $background: map-get($config, background);
  $foreground: map-get($config, foreground);

  .mat-expansion-panel {
    @include _mat-theme-overridable-elevation(2, $config);
    background: mat-color($background, card);
    color: mat-color($foreground, text);
  }

  .mat-action-row {
    border-top-color: mat-color($foreground, divider);
  }

  .mat-expansion-panel {
    & .mat-expansion-panel-header.cdk-keyboard-focused,
    & .mat-expansion-panel-header.cdk-program-focused,
    &:not(.mat-expanded) .mat-expansion-panel-header:hover {
      &:not([aria-disabled='true']) {
        background: mat-color($background, hover);
      }
    }
  }

  // Disable the hover on touch devices since it can appear like it is stuck. We can't use
  // `@media (hover)` above, because the desktop support browser support isn't great.
  @media (hover: none) {
    .mat-expansion-panel:not(.mat-expanded):not([aria-disabled='true'])
      .mat-expansion-panel-header:hover {
      background: mat-color($background, card);
    }
  }

  .mat-expansion-panel-header-title {
    color: mat-color($foreground, text);
  }

  .mat-expansion-panel-header-description,
  .mat-expansion-indicator::after {
    color: mat-color($foreground, secondary-text);
  }

  .mat-expansion-panel-header[aria-disabled='true'] {
    color: mat-color($foreground, disabled-button);

    .mat-expansion-panel-header-title,
    .mat-expansion-panel-header-description {
      color: inherit;
    }
  }
}

@mixin mat-expansion-panel-typography($config-or-theme) {
  $config: mat-get-typography-config($config-or-theme);
  .mat-expansion-panel-header {
    font: {
      family: mat-font-family($config, subheading-1);
      size: mat-font-size($config, subheading-1);
      weight: mat-font-weight($config, subheading-1);
    }
  }

  .mat-expansion-panel-content {
    @include mat-typography-level-to-styles($config, body-1);
  }
}

@mixin _mat-expansion-panel-density($config-or-theme) {
  $density-scale: mat-get-density-config($config-or-theme);
  $expanded-height: _mat-density-prop-value(
        $mat-expansion-panel-header-density-config, $density-scale, expanded-height);
  $collapsed-height: _mat-density-prop-value(
      $mat-expansion-panel-header-density-config, $density-scale, collapsed-height);

  @include _mat-density-legacy-compatibility() {
    .mat-expansion-panel-header {
      height: $collapsed-height;

      &.mat-expanded {
        height: $expanded-height;
      }
    }
  }
}

@mixin mat-expansion-panel-theme($theme-or-color-config) {
  $theme: _mat-legacy-get-theme($theme-or-color-config);
  @include _mat-check-duplicate-theme-styles($theme, 'mat-expansion-panel') {
    $color: mat-get-color-config($theme);
    $density: mat-get-density-config($theme);
    $typography: mat-get-typography-config($theme);

    @if $color != null {
      @include mat-expansion-panel-color($color);
    }
    @if $density != null {
      @include _mat-expansion-panel-density($density);
    }
    @if $typography != null {
      @include mat-expansion-panel-typography($typography);
    }
  }
}
